/* Copyright  2009
   @Author
   Richard Changde Yin            e-mail yinchangde@hotmail.com

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/**
 * @filename: esql_res.h
 */

#ifndef __LIBCLIENT_ESQL_RES_H__
#define __LIBCLIENT_ESQL_RES_H__

#include "esql_field.h"
#include "esql_data.h"
#include "esql_rows.h"
#include "esql.h"

#include <stdint.h>
#if !defined(__cplusplus)
# include <stdbool.h>
#endif

#ifdef  __cplusplus
extern "C" {
#endif

  struct st_esql;

  typedef struct st_esql_res {
  uint64_t  row_count;
  ESQL_FIELD  *fields;
  ESQL_DATA  *data;
  ESQL_ROWS  *data_cursor;
  uint32_t *lengths;    /* column lengths of current row */
  struct st_esql *handle;    /* for unbuffered reads */
  const struct st_esql_methods *methods;
  ESQL_ROW  row;      /* If unbuffered read */
  ESQL_ROW  current_row;    /* buffer to current row */
  uint32_t  field_count, current_field;
  bool  eof;      /* Used by client_fetch_row */
  /* esql_stmt_close() had to cancel this result */
  bool  unbuffered_fetch_cancelled;
  void *extension;
} ESQL_RES;


/*
  Functions to get information from the ESQL and ESQL_RES structures
  Should definitely be used if one uses shared libraries.
*/

uint64_t  client_num_rows(const ESQL_RES *res);
unsigned int  client_num_fields(const ESQL_RES *res);
bool  client_eof(const ESQL_RES *res);
const ESQL_FIELD * client_fetch_field_direct(const ESQL_RES *res,
                unsigned int fieldnr);
const ESQL_FIELD * client_fetch_fields(const ESQL_RES *res);
ESQL_ROW_OFFSET client_row_tell(const ESQL_RES *res);
ESQL_FIELD_OFFSET client_field_tell(const ESQL_RES *res);

void     client_free_result(ESQL_RES *result);
void     client_data_seek(ESQL_RES *result, uint64_t offset);
ESQL_ROW_OFFSET  client_row_seek(ESQL_RES *result, ESQL_ROW_OFFSET offset);
ESQL_FIELD_OFFSET  client_field_seek(ESQL_RES *result,ESQL_FIELD_OFFSET offset);
ESQL_ROW   client_fetch_row(ESQL_RES *result);
uint32_t *    client_fetch_lengths(ESQL_RES *result);
ESQL_FIELD *   client_fetch_field(ESQL_RES *result);

#ifdef  __cplusplus
}
#endif

#endif /* __LIBCLIENT_ESQL_RES_H__ */
